package com.easyjava.qingke.memo.command.impl;

import com.easyjava.qingke.memo.command.SystemCommand;
import com.easyjava.qingke.memo.util.MemoConsole;

public class DeleteCommand extends SystemCommand {

	public void excute() {

		MemoConsole.println("1.删除备忘录");
		MemoConsole.println("2.删除标签");
		MemoConsole.println("3.删除备忘录上的标签");

		int id = MemoConsole.promptInt("请输入想要操作的数字：");
		while (id > 0) {
			if (1 == id) {
				deleteMemoContent();
				break;
			} else if (2 == id) {
				deleteLabel();
				break;
			} else if (3 == id) {
				deleteMemoLabel();
				break;
			} else
				MemoConsole.println("输入的数字不存在！");
			id = MemoConsole.promptInt("请重新输入想要操作的数字：");
		}

	}

	private void deleteMemoLabel() {
		dao.selectMemoLabel();
		MemoConsole.println();
		int memoLabelId=MemoConsole.promptInt("请输入想要删除的备忘录上标签的ID：");
		while(!dao.isMemoLabelIdExists(memoLabelId)){
			MemoConsole.println("该ID不存在！");
			 memoLabelId=MemoConsole.promptInt("请重新输入想要删除的备忘录上标签的ID：");
		}
		dao.deleteMemoLabel(memoLabelId);

	}

	private void deleteLabel() {
		dao.selectLabel();
		MemoConsole.println();
		int id = MemoConsole.promptInt("请输入想要删除的标签ID：");
		while (!dao.isLabelIdExists(id)) {
			MemoConsole.println("该ID不存在！");
			id = MemoConsole.promptInt("请重新输入想要删除的标签ID：");
		}
		dao.deleteMemoLabelByLabelId(id);
		dao.deleteLabel(id);
	}

	private void deleteMemoContent() {
		dao.selectMemoContent();

		MemoConsole.println();
		int id = MemoConsole.promptInt("请输入想要删除的备忘录ID：");
		while (!dao.isMemoContentIdExists(id)) {
			MemoConsole.println("该ID不存在！");
			id = MemoConsole.promptInt("请重新输入想要删除的备忘录ID：");
		}
		dao.deleteMemoLabelByMemoContentId(id);
		dao.deleteMemoContent(id);
	}

}
